<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of Acl
 *
 * @author Dennis
 */
class Tc_Acl extends Zend_Acl {

    private $_noAuth;
    private $_noAcl;

    public function __construct() {
        $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/acl.xml');
        $roles = $config->roles;
        $resources = $config->resources;
        $this->_addRoles($roles);
        $this->_addResources($resources);
    }

    public function _addRoles($roles) {
        foreach ($roles as $name => $parents) {
            if (!$this->hasRole($name)) {
                if($parents=="null") {
                    $parents = null;
                } else {
                    $parents = explode(',', $parents);
                }

                $this->addRole(new Zend_Acl_Role($name), $parents);
            }
        }
    }

    public function _addResources($resources) {
        foreach($resources as $module => $modelResource) {
            foreach ($modelResource as $permissions => $controllers) {
                foreach ($controllers as $controller => $actions) {
                    if ($controller == 'all') {
                        $controller = null;
                    } else {
                        if (!$this->has($module.$controller)) {
                            $this->add(new Zend_Acl_Resource($module.$controller));
                        }
                    }

                    foreach ($actions as $action => $role) {
                        if ($action == 'all') {
                            $action = null;
                        }
                        if ($permissions == 'allow') {
                            $this->allow($role, $module.$controller, $action);
                        }
                        if ($permissions == 'deny') {
                            $this->deny($role, $module.$controller, $action);
                        }
                    }
                }
            }
        }
    }
}


?>
